//
//  ViewController.swift
//  DoubleVCShow
//
//  Created by dqw on 15/8/11.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.backgroundColor = UIColor.lightTextColor()
    
    }
    
    override func loadView() {
        super.loadView()
        let view1 = vc1.view
        let view2 = vc2.view
        view.addSubview(view1)
        view.addSubview(view2)
        view1.frame = view.bounds
        view2.frame = view.bounds
        vc1.view.layer.zPosition = 1
//        vc2.view.layer.zPosition = 2
        view.bringSubviewToFront(vc2.view)
        print(vc2.view.layer.zPosition)
//        view1.frame.size.width = view2.frame.origin.x
//        view1.frame.origin.x  = view.bounds.width
    }
    
    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
      let touch = touches.first
        let point = touch?.locationInView(view)
        vc2.view.frame.origin.x = (point?.x)!
        vc1.view.center = CGPoint(x: 0, y: UIScreen.mainScreen().bounds.height * 0.5)
//        vc1.view.frame.size.width = vc2.view.frame.origin.x
        vc1.view.layer.anchorPoint = CGPoint(x: 0, y:  0.5)
//        vc1.view.layer.position = CGPoint(x: 0, y: UIScreen.mainScreen().bounds.height * 0.5)
        
      let scale =    (point?.x)! / UIScreen.mainScreen().bounds.width  + 0.5
        vc1.view.transform = CGAffineTransformMakeScale(scale, scale)
         let z1 = vc1.view.layer.position
        vc1.view.layer.zPosition = (point?.x)!
//        let z2 = vc1.view.layer.zPosition
        vc1.view.layer.zPosition = 1
//
//        print(z1)
//        print(z2)
        
//        vc1.view.frame.size.height  = UIScreen.mainScreen().bounds.height * scale
//        vc1.view.frame.origin.y = point!.x * 0.8
//        vc1.view.alpha = scale * 0.5

    }
    
    private lazy var vc1: DDVC1 = DDVC1()
    private lazy var vc2: DDVC2 = DDVC2()



}

